<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <meta name="description" content="A fully featured admin theme which can be used to build CRM, CMS, etc.">
    <meta name="author" content="Coderthemes">

    <link rel="stylesheet" href="/adminstatic/base/base.css"/>
    <script src="/adminstatic/base/baseCss.js"></script>

    <style type="text/css">
        html, body {
            background: #fff;
        }

        .layui-input-block {
            margin-left: 0;
        }
    </style>
</head>

<body class="fixed-left">

<!-- Begin page -->
<div id="wrapper" style="overflow: auto;">

    <div class="container">

        <div class="panel panel-default" style="box-shadow: none">
            <div class="panel-body">
                <div class="layui-form">
                    <input type="hidden" name="id" value="<%=id%>"/>

                    <div class="form-group">
                        <div class="col-xs-12 col-md-4 ">
                            <label> <small class="notNullFlag">*</small>选择图片:</label>
                            <div class="layui-form-item">
                                <div class="layui-input-inline layui-btn-container" style="width: auto;">
                                    <button type="button" class="layui-btn layui-btn-primary" id="LAY_avatarUpload">
                                        <i class="layui-icon">&#xe67c;</i>上传图片
                                    </button>
                                </div>
                            </div>

                            <div class="layui-input-inline" id="avatar-preview">
                                <input type="hidden" name="pic" value="<%=pic%>"/>
                                <div class="img-item">
                                    <img style="width: 100%;height: 100%;" src="" onclick="showimg(this)">
                                    <div class="delete-item" onclick="deleteImg(this)">
                                        <i class="layui-icon layui-icon-close-fill"></i>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div id="actions">
                <button type="button" class="layui-btn layui-btn-normal" id="submitBtn">保存</button>
                <button type="button" class="layui-btn layui-btn-primary" onclick="closeIframe()">取消</button>
            </div>
        </div><!-- panel-body -->
    </div> <!-- panel -->

</div> <!-- container -->

</div>
<!-- END wrapper -->

<script src="/adminstatic/base/base.js"></script>
<script type="text/javascript">

</script>

<script type="text/javascript">
    var pic = $("input[name='pic']").val();
    $(".img-item img").attr("src", pic)

    //上传图片
    uploadImg('#LAY_avatarUpload', '/admin/upload/carouselImages/addFile', '#avatar-preview')

    function deleteImg(that) {
        var $this = $(that);
        $this[0].parentNode.remove()
        layer.msg(res.content, {icon: 1});
    }

    $("#submitBtn").click(function () {
        var id = $("input[name='id']").val();
        var pic = $('.img-item img').attr('src');
        console.log(pic)
        if (!vaildeParam(pic)) {
            layer.msg("请选择一张图片", {icon: 5});
            return;
        }

        var api = '/admin/carouselImage/update';
        var data = {
            "id": id,
            "pic": pic
        }

        postJSON(api, data, function (res) {
            cleanSuccess(res)
        })

    })
</script>


</body>
</html>